package leetcode;

import java.util.TreeSet;

/**
 * @author noob
 * @version 1.0
 * @date 2021/3/18 11:07
 *
 *
 */
public class Solution804 {
    public int uniqueMorseRepresentations(String[] words) {
        String[] codes= {".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."};

        TreeSet<String> set = new TreeSet<>();
        for(String word : words){ //遍历传进来的单词字符数组
            StringBuilder res = new StringBuilder();
            for (int i = 0; i < word.length(); i++) {
                res.append(codes[word.charAt(i) - 'a']);//获取偏移量，通过下标获取摩斯码
            }

            set.add(res.toString());
        }

        return  set.size();
    }

    public static void main(String[] args) {

         String[] words = {"gin", "zen", "gig", "msg"};
        int i = new Solution804().uniqueMorseRepresentations(words);
        System.out.println(i);
    }
    /**
     * word.charAt(i) - 'a'  g  == 6   ==>
     */

}
